// 文件打开处理工具
function openFile(fileData, fileName, fileType) {
    return new Promise((resolve, reject) => {
      const fs = wx.getFileSystemManager();
      const filePath = `${wx.env.USER_DATA_PATH}/${fileName}`;
      
      fs.writeFile({
        filePath,
        data: fileData,
        encoding: 'binary',
        success: () => {
          wx.openDocument({
            filePath,
            fileType,
            success: resolve,
            fail: reject
          });
        },
        fail: reject
      });
    });
  }
  
  // 获取文件类型
  function getFileType(fileName) {
    if (!fileName) return '';
    const ext = fileName.split('.').pop().toLowerCase().trim();
    return ext;
  }
  
  module.exports = {
    openFile,
    getFileType
  };